#ifndef __BaseApplication_h_
#define __BaseApplication_h_

#include <ogre.h>
#include <OgreStringConverter.h>
#include <OgreException.h>
#include "SoundManager.h"

#include <CEGUI.h>
#include <CEGUISystem.h>
#include <CEGUISchemeManager.h>
#include <OgreCEGUIRenderer.h>

//Use this define to signify OIS will be used as a DLL
//(so that dll import/export macros are in effect)
#define OIS_DYNAMIC_LIB
#include <OIS/OIS.h>

using namespace Ogre;

class LoadingBar;
class Character;
class MainCharacter;

class BaseApplication : public Ogre::Singleton<BaseApplication>,  public FrameListener, public WindowEventListener, public OIS::KeyListener, public OIS::MouseListener
{
public:
	enum TypeVIEW {ORIGINAL,VIEW2D,VIEW_CAPOT,VIEW_COCKPIT };
	TypeVIEW currentView;
	BaseApplication(void);
	virtual ~BaseApplication(void);

	// pour les menus CEGUI
	virtual void menuCegui(void);
	virtual void menuFin(void);
	virtual void menuPause(void);
	virtual void menuDepart(void);
	virtual void menuFinGagner(void);

	// met ou enleve le jeu en pause
	void resume(void);


	virtual void go(void);
	SceneManager* getSceneManager() { return mSceneMgr; }
	OIS::Keyboard* getKeyInputDevice() { return mKeyboard; }
	OIS::Mouse* getMouseInputDevice() { return mMouse; }
	virtual void showFish( bool b)=0;
	const Ogre::Real& getScrollingSpeed() const { return scrollingSpeed; }
	virtual void toggleView() = 0;

protected:
	virtual bool setup();
	virtual bool configure(void);
	virtual void chooseSceneManager(void);
	virtual void createCamera(void);
	virtual void createFrameListener(void);
	virtual void createScene(void) = 0; // Override me!
	virtual void destroyScene(void);
	virtual void createViewports(void);
	virtual void setupResources(void);
	virtual void createResourceListener(void);
	virtual void loadResources(void);
	virtual void updateStats(void);
	virtual bool processUnbufferedKeyInput(const FrameEvent& evt);
	virtual bool processUnbufferedMouseInput(const FrameEvent& evt);
	virtual void moveCamera();
	virtual bool frameStarted(const FrameEvent& evt);
	virtual bool frameEnded(const FrameEvent& evt);

	void showDebugOverlay(bool show);
	void switchMouseMode();
	void switchKeyMode();
	bool keyPressed( const OIS::KeyEvent &arg );
	bool keyReleased( const OIS::KeyEvent &arg );
	bool mouseMoved( const OIS::MouseEvent &arg );
	bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
	bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id );

	


	//Adjust mouse clipping area
	virtual void windowResized(RenderWindow* rw);
	//Unattach OIS before window shutdown (very important under Linux)
	virtual void windowClosed(RenderWindow* rw);

	void requestShutdown(void);


	Root *mRoot;
	Camera* mCamera;
	SceneManager* mSceneMgr;
	RenderWindow* mWindow;
	LoadingBar* mLoadingBar;
	bool mShutdownRequested;
	int mSceneDetailIndex ;
	Real mMoveSpeed;
	Degree mRotateSpeed;
	Overlay* mDebugOverlay;
	std::string mDebugText;
	//OIS Input devices
	OIS::InputManager* mInputManager;
	OIS::Mouse*    mMouse;
	OIS::Keyboard* mKeyboard;
	Vector3 mTranslateVector;
	bool mStatsOn;
	bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
	unsigned int mNumScreenShots;
	float mMoveScale;
	Degree mRotScale;
	Real mTimeUntilNextToggle; // just to stop toggles flipping too fast
	Radian mRotX, mRotY;
	TextureFilterOptions mFiltering;
	int mAniso;

	MainCharacter* mMainCharacter;

	// pour mettre le jeu en pause
	bool pause;

	RaySceneQuery* raySceneQuery;

	// SoundManager with OpenAL and samples

	unsigned int generalSoundId;
	unsigned int startupSoundId;
	Ogre::Real scrollingSpeed;
};

#endif // #ifndef __BaseApplication_h_
